﻿using System;
using Mbl.ParameterizedTest.AcceptanceTests.CalculatorTests;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Mbl.ParameterizedTest.AcceptanceTests.GeneralExpectationTests
{
    [TestClass]
    public class EqualityTests
    {
        [TestMethod]
        [ExpectedFailedTestCases(2, 3)]
        public void Same_is_only_satisfied_by_exact_equality_tests()
        {            
            ParameterizedTest
                .For<string>(s => "asdf")
                .Given("asdf").ExpectTheSame().Because("It's an identity mapping")
                .Given("ASDF").ExpectTheSame().Because("It's only exact equality")
                .Given(null).ExpectTheSame().Because("It's only exact equality")
                .Evaluate();
        }

        [TestMethod]
        [ExpectedFailedTestCases(2, 3)]
        public void Same_with_null_output()
        {
            ParameterizedTest
                .For<string>(s => null)
                .Given(null).ExpectTheSame().Because("It's an identity mapping")
                .Given("asdf").ExpectTheSame().Because("It's an identity mapping")
                .Given(string.Empty).ExpectTheSame().Because("It's not null")
                .Evaluate();
        }

        [TestMethod]        
        public void Same_different_types()
        {
            try
            {
                ParameterizedTest
                    .For<string, int>(s => 0)
                    .Given("").ExpectTheSame().Because("It's an identity mapping")
                    .Evaluate();

                Assert.Fail("ExpectTheSame should not be possible between types that cannot be converted into each other.");
            }
            catch (InvalidCastException)
            {                
            }
        }
    }
}
